import os
from google.appengine.api import users
from google.appengine.ext.webapp import template
from google.appengine.ext import webapp
from google.appengine.ext import db
from awsmpg import AwesomePage
from sheet_model import Sheet
from sheet_model import SheetItem

class SheetEditPage(AwesomePage):
	def OnGet(self):
		sKey = self.request.get('key')
		if not sKey:
			newSheet = Sheet()
			newSheet.description = 'My new sheet'
			newSheet.put()
			self.redirect(self.request.path + '?key=' + str(newSheet.key()))
			return False
		else:
			self.RenderSheet(sKey)
		return True
	def RenderSheet(self, key):
		self.sheet = db.get(key)
		self.items = SheetItem.gql('WHERE sheet = :1', self.sheet)
	def IsSecure(self):
		return True
	def head_template(self):
		return "sheetedit.head.htm"
	def content_template(self):
		return "sheetedit.content.htm"
	def head_dataset(self):
		return {}
	def content_dataset(self):
		return {'items' : self.items, 'sheet' : self.sheet}
